/**
 * 初始化部门详情对话框
 */
var OutpatientManagementInfoDlg = {
    outpatientManagementInfoData : {},
    zTreeInstance : null,
    validateFields: {
        outpatientName: {
            validators: {
                notEmpty: {
                    message: '门诊名称不能为空'
                },
                stringLength: {
                    max: 20,
                    message: '门诊名称长度不能超过20，请重新输入...'
                }/*最后一个没有逗号*/
            }
        },
    }
};

/**
 * 清除数据
 */
OutpatientManagementInfoDlg.clearData = function() {
    this.outpatientManagementInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
OutpatientManagementInfoDlg.set = function(key, val) {
    this.outpatientManagementInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
OutpatientManagementInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
OutpatientManagementInfoDlg.close = function() {
    parent.layer.close(window.parent.OutpatientManagement.layerIndex);
}

/**
 * 收集数据
 */
OutpatientManagementInfoDlg.collectData = function() {
    this.set('id').set('outpatientName').set('remarks').set('num');
}

/**
 * 验证数据是否为空
 */
OutpatientManagementInfoDlg.validate = function () {
    $('#outpatientManagementInfoForm').data("bootstrapValidator").resetForm();
    $('#outpatientManagementInfoForm').bootstrapValidator('validate');
    return $("#outpatientManagementInfoForm").data('bootstrapValidator').isValid();
}

/**
 * 提交添加
 */
OutpatientManagementInfoDlg.addSubmit = function() {
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/outpatientManagement/add", function(data){
        Feng.success("添加成功!");
        window.parent.OutpatientManagement.table.refresh();
        OutpatientManagementInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.outpatientManagementInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
OutpatientManagementInfoDlg.editSubmit = function() {
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/outpatientManagement/update", function(data){
        Feng.success("修改成功!");
        window.parent.OutpatientManagement.table.refresh();
        OutpatientManagementInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.outpatientManagementInfoData);
    ajax.start();
}

function onBodyDown(event) {
    if (!(event.target.id == "menuBtn" || event.target.id == "parentOutpatientManagementMenu" || $(
            event.target).parents("#parentOutpatientManagementMenu").length > 0)) {
        OutpatientManagementInfoDlg.hideOutpatientManagementSelectTree();
    }
}

$(function() {
    Feng.initValidator("outpatientManagementInfoForm", OutpatientManagementInfoDlg.validateFields);
});
